package com.xxwu.messagequeue.demo;

import com.xxwu.messagequeue.mqclient.Channel;
import com.xxwu.messagequeue.mqclient.Connection;
import com.xxwu.messagequeue.mqclient.ConnectionFactory;
import com.xxwu.messagequeue.mqserver.core.ExchangeType;

import java.io.IOException;

public class Producer {
    public static void main(String[] args) throws IOException {
        // 创建客户端
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(9090);
        Connection connection = factory.createConnection();
        Channel channel = connection.createChannel();
        channel.createChannel();

        // 生产消息
        channel.exchangeDeclare("demoExchange", ExchangeType.Direct, true, false, null);
        channel.queueDeclare("demoQueue", true, false, false, null);
        channel.queueBind("demoExchange", "demoQueue", "");
        channel.basicPublish("demoExchange", "demoQueue", null, "Hello World".getBytes());

        channel.close();
        connection.close();
    }
}
